<div class="loader"></div>
<div class="row filter-form-container">
{{ Form::open(array('url' => $base, 'id' => 'form-filter')) }}
	{{-- Form Filter Fields --}}
	<div class='filter-form-group row'>
			<div class="col-md-6 form-group">
					{{ Form::label('filter_id', $text_filter_id) }}
					{{ Form::text('filter_id', Input::get('filter_id'), array('class' => 'form-control')) }}
					
					{{ Form::label('filter_po_number', $text_filter_po_number) }}
					{{ Form::text('filter_po_number', Input::get('filter_po_number'), array('class' => 'form-control')) }}
				
					{{ Form::label('filter_po_shipping', $text_filter_po_shipping) }}
					{{ Form::select('filter_po_shipping', $shippings, Input::get('filter_po_shipping'), array('class' => 'form-control')) }}
			</div>
			
			<div class="col-md-6 form-group">
				@if ( !empty($vendors) )
					{{ Form::label('filter_vendor', $text_filter_vendor) }}
					{{ Form::select('filter_vendor', $vendors, Input::get('filter_vendor'), array('class' => 'form-control')) }}
				@endif
		
				@if ( !empty($statuses) )
					{{ Form::label('filter_status', $text_filter_status) }}
					{{ Form::select('filter_status', $statuses, Input::get('filter_status'), array('class' => 'form-control')) }}
				@endif
			</div>
		<div class="clearfix"></div>
	</div>

	{{-- Form Filter Buttons --}}
	<div class="filter-btn-row row">
		{{ HTML::link(URL::to($base), $text_filter, array('class' => 'btn btn-default', 'id'=> 'filter')) }}
		<input type="Button" id="export_po_list"class="btn btn-warning" value="{{ $button_export_po }}"></input>
		<input type="Button" id="export_so" class="btn btn-primary" value="{{ $button_generate_sales }}"></input>
		<input type="Button" id="button_postUploadPurchaseOrderStatus" class="btn btn-success" value="{{ $button_upload_po_to_receiving }}"></input>
		<a class="btn btn-success btn-approve-po pull-right" id="approved_po">{{ $button_move_selected_to_received }}</a>
	</div>
{{ Form::close() }}
</div>
<p>&nbsp;</p>
{{ Form::open(array('url' => $base, 'id' => 'form_po_list')) }}
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
@foreach($results AS $key=>$value)
	<div class="row list-row">
	<div class="panel panel-default">
		<div class="panel-heading  po_status_{{ $value->status }} " role="tab" id="po-{{ $value->id }}">
		<a class="header-po-link" poid="{{ $value->id }}" data-toggle="collapse" data-parent="#accordion" href="#po-detail-{{ $value->id }}" aria-expanded="false" aria-controls="po-detail-{{ $value->id }}">
			PO # <strong>{{ strtoupper($value->vendor->code) }}-{{ str_pad($value->id, 3, '0', STR_PAD_LEFT) }}-{{ date_format($value->created_at, 'Ymd') }}</strong>&nbsp;<em>({{ $statuses[$value->status] }})</em></a>
			<div class="pull-right">
				<span class="text-success"><strong>{{ $value->purchaseOrderProducts()->where( array('receive_include' => '1', 'archived' => 0) )->count() }} out of {{  $value->purchaseOrderProducts()->where( array('archived' => 0) )->count() }} </strong></span>
				<a class="btn btn-info edit" href="{{ URL::to($base, array($value->id, 'edit')) }}" title="{{ $text_edit }}"><i class="fa fa-pencil"></i></a>
			</div>
		</div>
	</div>
	<div id="po-detail-{{ $value->id }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="po-{{ $value->id }}" >
		<div class="panel-body" id="po-detail-body-{{ $value->id }}">
			<table class="table table-bordered">
				<thead>
					<tr>	
						<td> {{ ($value->status == Constant::PO_APPROVED  && $value->purchaseOrderProducts()->where('receive_include','=',1)->count() != $value->purchaseOrderProducts()->count() ) ? Form::checkbox('po-id[]', $value->id, null, [ 'class' => 'form-control pull-left list_po_id', 'id'=>'po_id']) : '' }}</td>
						<th>{{ $list_item_id }}</th>
						<th>{{ $list_product_id }}</th>
						<th>{{ $list_product_name }}</th>
						<th>{{ $list_product_options }}</th>
						<th>{{ $list_product_model }}</th>
						<th>{{ $list_product_sku }}</th>
						<th>{{ $list_product_quantity }}</th>
						<th>{{ $list_product_srp }}</th>
						<th>{{ $list_product_transfer_price }}</th>
						<th>{{ $list_product_voucher_received }}</th>
						<th>{{ $list_product_voucher_desc }}</th>
					</tr>
				</thead>
				<tbody>
				@foreach( $value->purchaseOrderProducts as $po_items )
					<tr {{ ( $po_items->receive_include ) ? 'class="success"' : 'class="danger"' }} po-item-row="{{ $po_items->id }}">
						<td>{{ ( $po_items->orderProduct->status == Constant::ORDER_ORDERED_FROM_SUPPLIER && $value->status == Constant::PO_APPROVED ) ? Form::checkbox('purchase_order_product[' . $po_items->PURCHASE_ORDER_id . '][]', $po_items->id, null, [ 'class' => 'form-control po-product']) : ''}}</td>
						<td>{{ $po_items->ORDER_PRODUCT_id }}</td>
						<td>{{ $po_items->orderProduct->PRODUCT_id }}</td>
						<td>{{ $po_items->orderProduct->product->name }}</td>
						<td>
							@if ( $po_items->orderProduct->orderProductOptions->count() )
								@foreach ( $po_items->orderProduct->orderProductOptions as $option )
									{{ $option['option_value'] }} (+{{ number_format($option['price'],2) }}) - {{ $option['quantity'] }} <br/>
								@endforeach
							@else
								N/A
							@endif
						</td>
						<td>{{ $po_items->orderProduct->product->code }}</td>
						<td>{{ $value->vendor->code }}-{{ $po_items->orderProduct->model }}</td>
						<td>{{ $po_items->quantity }}</td>
						<td>{{ number_format($po_items->srp, 2) }}</td>
						<td>{{ number_format($po_items->transfer_price, 2) }}</td>
						<td class="po-item-voucher-status-{{ $po_items->id }}">{{ $voucher_receive_status[(int)$po_items->purchaseOrderProductVoucher['received']] }}</td>
						<td>
							@if($po_items->orderProduct->product->voucher == Constant::IS_VOUCHER)
								<a href="{{ URL::to('po/sendVoucher/' . $po_items->orderProduct->PRODUCT_id) }}?po_item_id={{ $po_items->id }}" class="btn btn-default send-voucher" title="{{ $text_send_voucher }}" po-item="{{ $po_items->id }}"><i class="fa fa-envelope"></i></a>
								<a href="{{ URL::to('po/viewVoucher/' . $po_items->orderProduct->PRODUCT_id) }}?po_item_id={{ $po_items->id }}" class="btn btn-default preview-voucher" title="{{ $text_view_voucher_desc }}" po-item="{{ $po_items->id }}"><i class="fa fa-search"></i></a>
								<a href="{{ URL::to('po/editVoucher/' . $po_items->orderProduct->PRODUCT_id) }}?po_item_id={{ $po_items->id }}" class="btn btn-default edit-voucher" data-toggle="modal" data-target="#general-modal"  po-item="{{ $po_items->id }}"><i class="fa fa-pencil"></i></a>
								<div class="trace-po-{{ $po_items->id }}"></div>
							@else
								<i>{{ $text_non_voucher }}</i>
							@endif
						</td>
					</tr>
					
				@endforeach
				</tbody>
			</table>
		</div>
	</div>
	</div>
@endforeach
</div>
{{ Form::close() }}
<div class="box-footer">
	<div class="col-xs-14 text-center">
		<div class="dataTables_info">Showing {{ $results->getFrom() }} to {{ $results->getTo() }} of {{ $results->getTotal() }} entries</div>
	</div>
	<div class="col-xs-14 text-center">
		<div class="no-margin">
		{{ $results->appends(Input::all())->links() }}
		</div>
	</div>
</div>
<script src="{{ Asset::bea('javascript/jquery/jquery.' . Backtrack::getRouteName() . '-list.js') }}"></script>
